package com.chenchao.method;

import java.util.function.Consumer;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/4 16:29
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.method.Test04.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 函数式接口Consumer
 */
public class Test04 {
    public static void main(String[] args) {
        /*只关心参数*/
        String str="吃葡萄不吐葡萄皮";

        /*注重执行方法*/
        consumer(str, System.out::println);
        consumerTwo(str, System.out::println,s -> {
            System.out.println(new StringBuilder(s).reverse());
        });
    }
    public static void consumer( String str,Consumer<String> consumer){
        consumer.accept(str);
    }
    /*相当于把参数与执行方法进行拼接*/
    /**
     * 使用andThen执行两个
     * @param str  str
     * @param consumer1 consumer1
     * @param consumer2 consumer2
     */
    public static void consumerTwo( String str,Consumer<String> consumer1,
                                    Consumer<String> consumer2){
        consumer1.andThen(consumer2).accept(str);
    }
}
